<?php

namespace App\Api\Controllers;

use App\Api\Dao\UserBankDao;
use App\Api\Logic\UserBankLogic;
use App\Exceptions\DaoException;
use App\Exceptions\ValidationException;
use Illuminate\Http\Request;

class UserBankController extends BaseController
{
    /**
     * 添加银行卡
     * @param Request $request
     * @param UserBankLogic $userBankLogic
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ValidationException
     * @throws DaoException
     */
    public function addBank(Request $request,UserBankLogic $userBankLogic,UserBankDao $userBankDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userBankLogic->addBank($data);
        $result = $userBankDao->addBank($data);
        return $this->success($result);
    }

    /**
     * 银行卡编辑
     * @param Request $request
     * @param UserBankLogic $userBankLogic
     * @param UserBankDao $userBankDao
     * @return \Illuminate\Http\JsonResponse
     */
    public function editBank(Request $request,UserBankLogic $userBankLogic,UserBankDao $userBankDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userBankLogic->editBank($data);
        $result = $userBankDao->editBank($data);
        return $this->success($result);
    }

    /**
     * 获取银行卡的列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function getBankList(Request $request,UserBankDao $userBankDao){
        $data = ['u_id'=>$request->u_id];
        $result = $userBankDao->getBankList($data);
        return $this->success($result);
    }

    /**
     * 获取银行卡的详情
     * @param Request $request
     * @param UserBankLogic $userBankLogic
     * @param UserBankDao $userBankDao
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function bankInfo(Request $request,UserBankLogic $userBankLogic,UserBankDao $userBankDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userBankLogic->bankInfo($data);
        $result = $userBankDao->bankInfo($data);
        return $this->success($result);
    }

    /**
     * 删除银行卡
     * @return \Illuminate\Http\JsonResponse
     */
    public function delBank(Request $request,UserBankLogic $userBankLogic,UserBankDao $userBankDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userBankLogic->delBank($data);
        $result = $userBankDao->delBank($data);
        return $this->success($result);
    }
}
